package com.ar.engine.objLoader;

public class Vector3D {

	private float x;
	private float y;
	private float z;
	private float magnitude;
	
	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

	public void setZ(float z) {
		this.z = z;
	}

	public Vector3D getNormalized()
	{
		double mag = this.magnitude;
		
		this.x /= mag;
		this.y /= mag;
		this.z /= mag;
		
		return this;
	}
	
	public float getMagnitude()
	{
		 magnitude = (float) (Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z));
		 return magnitude;
	}
	
	public float getX()
	{
		return this.x;
	}
	
	public float getY()
	{
		return this.y;
	}
	
	public float getZ()
	{
		return this.z;
	}
	
	public Vector3D()
	{
		this.x = 0;
		this.y = 0;
		this.z = 0;
	}
	
	public Vector3D(float X, float Y, float Z)
	{
		this.x = X;
		this.y = Y;
		this.z = Z;
	}
	
	public static Vector3D Add(Vector3D vector1, Vector3D vector2)
	{
		return new Vector3D(vector1.getX() + vector2.getX(), vector1.getY() + vector2.getY(), vector1.getZ() + vector2.getZ());
	}
	
	public static Vector3D Subtract(Vector3D vector1, Vector3D vector2)
	{
		return new Vector3D(vector1.getX() - vector2.getX(), vector1.getY() - vector2.getY(), vector1.getZ() - vector2.getZ());
	}
	
	public static Vector3D Multiply(Vector3D vector1, Vector3D vector2)
	{
		return new Vector3D(vector1.getY() * vector2.getZ() - vector1.getZ() * vector2.getY(),
                -(vector1.getX() * vector2.getZ() - vector1.getZ() * vector2.getX()),
                vector1.getX() * vector2.getY() - vector1.getY() * vector2.getX());
	}
}
